<template>
    <div class="e-table billList">
        <TopStep :stepInfo="stepInfo" />
        <div class="top">
            <div class="left" style="margin-left: 10px">
                <div>
                    <el-button
                        size="mini"
                        @click="buttonAdd"
                        style="background: #7aa818; color: #fff"
                        >新增</el-button
                    >
                </div>
            </div>
            <div class="right">
                <div class="right-div1">
                    <el-input
                        placeholder=""
                        v-model="query.keyWord"
                        size="small"
                    >
                        <i
                            slot="suffix"
                            class="el-icon-search like"
                            @click="getData"
                        ></i>
                    </el-input>
                </div>
                <div>
                    <el-button
                        size="small"
                        style="background: #2e61d7; color: #fff"
                         @click="advancedSearchEvent"
                        >高级搜索</el-button
                    >
                </div>
            </div>
        </div>

        <el-table
            border
            ref="table"
            :data="tableData"
            style="width: 100%"
            class="table"
            highlight-current-row
            height="0"
            v-sortTable="{ 'tableData': tableData, '_this': this, 'ref': 'table' }"
        >
            <el-table-column
                label="结算编号"
                min-width="170"
                fixed
                show-overflow-tooltip
            >
                <template slot-scope="scope">
                    <span
                        @click="Examine(scope.row)"
                        style="color: blue; cursor: pointer"
                    >
                        {{ scope.row.billNo }}
                    </span>
                </template>
            </el-table-column>
            <el-table-column
                fixed
                prop="settleDate"
                label="结算日期"
                width="150">
            </el-table-column>
            <el-table-column
                prop="orgName"
                label="出租单位"
                min-width="200"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="settleOrg"
                label="结算单位"
                min-width="150"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="settleAmount"
                label="结算金额（元）"
                min-width="100"
            >
            </el-table-column>
            <el-table-column
                prop="totalSettleAmount"
                label="累计结算金额（元）"
                width="100"
            >
            </el-table-column>
              <el-table-column
                label="源单编号"
                width="100"
                prop="sourceNo"
            >
                <template v-slot="{ row }">
                    <span
                        style="color: blue; cursor: pointer"
                        @click="seeSourceOrder(row)"
                        >{{ row.sourceNo }}</span
                    >
                </template>
             </el-table-column>
            <el-table-column label="状态" prop="currentStatus" show-overflow-tooltip width="100">
                <template slot-scope="{ row,$index }">
                    <ToolHistory v-if="row.state == 1" :key="$index" url="/materialsettle/flowEngin/getAuditHistory" :billId="row.billId" :billType="6099">
                        <span v-status="row.state">
                            {{row.currentStatus}}
                        </span>
                    </ToolHistory>
                    <span v-else v-status="row.state">
                        {{row.currentStatus}}
                    </span>
                </template>
            </el-table-column>
            <el-table-column label="红单状态" width="100" prop="redState">
            <template slot-scope="{ row }" >
                    <span
                    @click="goToRed(row)"
                    style="color: blue; cursor: pointer"
                    >{{row.redState}}
                    </span>
            </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <ComPagination
            :total="total"
            :pageSize.sync="query.limit"
            :currentPage.sync="query.page"
            @currentChange="getData"
            @sizeChange="getData"
            class="bottomSetting"
        />
    </div>
</template>
<script>
import ComPagination from '@/components/pagination/pagination.vue'
import TopStep from '@/components/topstep/topstep'
import { vueDom, debounce, openAppClient, advanceSearch } from '@/utils/common.js'
import request from '@/api/settlementManagement/weeklyMaterialSettlement/internalRentTransferSettlement.js'
import publicRequest from '@/api/settlementManagement/publicRequest/publicRequest.js'
export default {
    components: {
        ComPagination,
        TopStep
    },
    data () {
        return {
            tableData: [],
            query: {
                keyWord: '',
                limit: 20,
                page: 1,
                search: {
                    'endTime': '',
                    'orgId': '',
                    'settleOrgName': '',
                    'startTime': '',
                    'states': []
                }
            },
            total: 0,
            tableHeight: 0,
            auditParams: {
                billId: '',
                billType: 6099,
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: ''
            },
            //标题进度
            stepInfo: [
                {
                    description: '周材内租调用'
                },
                {
                    description: '周材入库'
                },
                {
                    description: '内租调动结算'
                },
            ]
        }
    },
    computed: {
    },
    created () {
        this.getData()
    },
    mounted () {
        // table动态高度
        vueDom(
            () => {
                this.tableHeight = document.body.clientHeight - 240
            },
            () => {
                return $('table').length !== 0
            }
        )
        this.fn = () => {
            this.tableHeight = document.body.clientHeight - 240
        }
        window.onresize = debounce(this.fn)
    },
    methods: {
        // 获取列表数据
        async getData () {
            const res = await request.getInternalRentTransferData(this.query)
            const data = res.list
            //状态
            const obj = {
                '-1': '已删除',
                '0': '草稿',
                '1': '审核中',
                '2': '已审核',
                '5': '已作废'
            }
            //红单状态
            const redState = {
                '-1': '',
                '0': '冲销中',
                '1': '冲销中',
                '2': '已冲',
                '3': '红单'
            }
            data.forEach(item => {
                item.currentStatus = obj[item.state]
                item.isRed = item.redState
                item.redState = redState[item.redState]
            })
            this.tableData = data
            this.total = res.totalCount
        },
        //新增按钮
        buttonAdd () {
            this.$router.push('/internalRentTransferSettlementAdd')
        },
        //点击编号
        Examine (row) {
            //判断是否为红单3为红单
            if(row.isRed == 3) {
                this.$router.push({
                    path: '/internalRentTransferSettlementRed',
                    query: { billid: row.billId }
                })
                return
            }
            if (row.state === -1 || row.state === 2 || row.state === 5) {
                this.$router.push({
                    path: '/internalRentTransferSettlementDetail',
                    query: { billid: row.billId }
                })
            } else {
                this.auditParams.billId = row.billId
                publicRequest.adoptIdObtainGetButtonsData(this.auditParams).then(res => {
                    if (res.canModify == true) {
                        this.$router.push({
                            path: '/internalRentTransferSettlementEdit',
                            query: { billid: row.billId }
                        })
                    } else {
                        this.$router.push({
                            path: '/internalRentTransferSettlementDetail',
                            query: { billid: row.billId }
                        })
                    }
                })
            }
        },
        //查看源单页面
        seeSourceOrder (row) {
            openAppClient(
            `/revolveInternalLeaseTransferShow?billid=${row.sourceId}&isview=true`, '查看内租调动页面'
            )
        },
        //点击红单
        goToRed (row) {
            //判断是否为红单
            //relationId为对应的关联id
            if(row.isRed == 3) {
                this.$router.push({
                    path: '/internalRentTransferSettlementDetail',
                    query: { billid: row.relationId }
                })
                return
            }else {
                this.$router.push({
                    path: '/internalRentTransferSettlementRed',
                    query: { billid: row.relationId }
                })
                return
            }
        },
        // 高级搜索
        advancedSearchEvent () {
            advanceSearch('/internalRentTransferSettlementSearch')
                .then(res=>{
                    this.query.keyWord = ''
                    this.query.limit = 20
                    this.query.page = 1
                    this.query.search = res
                    this.getData()
                })
        }
    }
}
</script>
<style lang="scss" scoped>
// .like {
//     color: rgb(46, 97, 215);
//     font-size: 17px;
//     line-height: 30px;
//     cursor: pointer;
// }
::v-deep.el-table .cell {
    text-align: center;
}

.e-table {
    min-height: 97.3vh;
}
</style>
